<template>
	<view>
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="收货地址" :autoBack="true">
			</u-navbar>
		</view>
		<view class="con-body">
			<u-empty :show="shownull" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
			<view class="item" v-for="(res, index) in siteList" :key="res.id">
				<view class="top">
					<view class="name">{{ res.name }}</view>
					<view class="phone">{{ res.phone }}</view>
					<view class="tag">
						<text v-if="res.label==1" class="red">默认</text>
						<text v-else>普通</text>
					</view>
				</view>
				<view class="bottom">
					{{res.address}}{{res.address_detail}}
					<u-icon name="edit-pen" :size="40" color="#999999" @click="toAddSite(res.id,res)"></u-icon>
				</view>
			</view>
			<view class="addSite" @click="toAddSite(0)">
				<view class="add">
					<u-icon name="plus" color="#ffffff" class="icon" :size="20"></u-icon>新建收货地址
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
import { getAddress } from "@/service/shopservice.js";
export default {
	data() {
		return {
			siteList: [],
			shownull:false,
		};
	},
	onShow() {
		getAddress().then(this.getAddress);
	},
	methods: {
		getAddress(e) {
			// console.log(e);
			if(e.code==200){
				this.shownull=false;
				this.siteList=e.result;
			}else{
				this.shownull=true;
				this.siteList=[];
			}
		},
		toAddSite(id,item){
			// console.log('111');
			if(id!=0){
				this.$u.route({
					url: '/pagesShop/mine/addSite',
					params: {
						id: id,
						name: item.name,
						phone:item.phone,
						address:item.address,
						address_detail:item.address_detail,
						label:item.label
					}
				});
			}else{
				this.$u.route({
					url: '/pagesShop/mine/addSite',
					params: {
						id: id
					}
				});
			}
			
			// uni.navigateTo({
			//     url: '/pagesShop/mine/addSite?id='+id
			// });
		}
	}
};
</script>

<style lang="scss" scoped>
.item {
	padding: 40rpx 20rpx 20rpx;
	background-color: #fff;
	margin-bottom:20rpx;
	.top {
		display: flex;
		// font-weight: bold;
		font-size: 32rpx;
		.phone {
			margin-left: 60rpx;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color:#0B868E;
			}
			.red{
				background-color:red
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;
	}
}
.addSite {
	display: flex;
	justify-content: space-around;
	width: 600rpx;
	line-height: 80rpx;
	position: absolute;
	bottom: 30rpx;
	left: 80rpx;
	background-color: #ff5500;
	border-radius: 60rpx;
	font-size: 30rpx;
	.add{
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon{
			margin-right: 10rpx;
		}
	}
}
</style>
